package org.shopen.ai.puremvc.model.algo
{
	import org.shopen.ai.puremvc.model.problem.IAction;
	import org.shopen.ai.puremvc.model.problem.IProblem;
	import org.shopen.ai.puremvc.model.problem.IState;

	public class SearchNode implements ISearchNode
	{
		protected var _action : IAction = null;
		public function get action() : IAction
		{
			return _action;
		}
		
		protected var _state : IState = null;
		public function get state():IState
		{
			return _state;
		}
		
		protected var _parent : ISearchNode = null;
		public function get parent():ISearchNode
		{
			return _parent;
		}
		
		/* protected var _children : ArrayCollection = new ArrayCollection();
		public function get children():ArrayCollection
		{
			return null;
		} */
		
		public function get depth():uint
		{
			var result : uint = 0;
			if (parent != null)
			{
				result = parent.depth + 1;
			}
			return result;
		}
		
		public function get hash() : uint
		{
			return state.hash;
		}
		
		public function SearchNode(state : IState, action : IAction = null, parent : ISearchNode = null, pathCost : Number = 0)
		{
			this._state = state;
			this._action = action;
			this._parent = parent;
			this._pathCost = pathCost
		}

		protected var _pathCost : Number = 0;
		public function get pathCost():Number
		{
			var result : Number = _pathCost;
			return result;
			if (parent != null)
			{
				result += parent.pathCost;
				if (action != null)
				{
					result += problem.costFunction.getCost(parent.state, action);
				}
			}
			return result;
		}
		
		public function toString():String
		{
			return state.toString();
		}
	}
}